import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sgy_flutter/ble/ble_manager.dart';
import 'package:sgy_flutter/extensions/get.dart';
import 'package:sgy_flutter/page/adjust_zero/view.dart';
import 'package:sgy_flutter/page/detail/logic.dart';
import 'package:sgy_flutter/page/dfu/view.dart';
import 'package:sgy_flutter/page/other_settings/view.dart';
import 'package:sgy_flutter/widget/shadow_container.dart';

class ButtonView extends GetView<DetailLogic> {
  const ButtonView({super.key});

  @override
  Widget build(BuildContext context) {
    var borderRadius = BorderRadius.circular(6);

    final decoration = BoxDecoration(
      borderRadius: borderRadius,
      color: Color(0xfff1f2f3),
      boxShadow: [
        BoxShadow(color: Colors.black26, offset: Offset(0, 0), blurRadius: 1)
      ],
    );
    const double margin = 10;
    const textStyle = TextStyle(fontSize: 16, color: Colors.grey);
    const double height = 44;
    return Obx(() => Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            ShadowContainer(
              height: height,
              borderRadius: borderRadius,
              child: Center(
                child: Text(
                  "零点校准".tr,
                  style: textStyle.copyWith(
                      color:
                          controller.ready.isTrue ? Colors.black : Colors.grey),
                ),
              ),
              enable: controller.ready.isTrue,
              onTap: controller.ready.isFalse ? null : () async {
                await Get.to(() => const AdjustZeroPage(),
                    arguments: controller.deviceModel);
              },
            ).marginOnly(bottom: margin),
            ShadowContainer(
                height: height,
                borderRadius: borderRadius,
                enable: controller.ready.isTrue,
                onTap: controller.ready.isFalse ? null : () {
                  Get.to(() => DfuPage(), popGesture: false);
                },
                child: Center(
                  child: Badge(
                    isLabelVisible: controller.bleManager.hasNewFirmware.value|| controller.rightBleManager.hasNewFirmware.value,
                    backgroundColor: Colors.transparent,
                    offset: const Offset(12, 1),
                    label: Container(
                      width: 10,
                      height: 10,
                      decoration: BoxDecoration(
                        color: Colors.red,
                        borderRadius: BorderRadius.circular(5),
                      ),
                    ),
                    child: Text(
                      "固件升级".tr,
                      style: textStyle.copyWith(
                          color: controller.ready.isTrue
                              ? Colors.black
                              : Colors.grey),
                    ),
                  ),
                )).marginOnly(bottom: margin),
            ShadowContainer(
                height: height,
                borderRadius: borderRadius,
                enable: controller.ready.isTrue,
                onTap: controller.ready.isFalse ? null : () {
                  Get.to(() => OtherSettingsPage());
                },
                child: Center(
                  child: Text(
                    "其他设置".tr,
                    style: textStyle.copyWith(
                        color: controller.ready.isTrue
                            ? Colors.black
                            : Colors.grey),
                  ),
                )).marginOnly(bottom: margin),
          ],
        )).paddingSymmetric(horizontal: 16, vertical: 12);
  }
}
